<template>
  <div v-if="show" class="promotion-modal">
    <div class="modal-overlay" @click="closeModal"></div>
    <div class="modal-content">
      <span class="close" @click="closeModal">&times;</span>
      <h2>{{ isEditing? '编辑促销活动' : '添加新促销活动' }}</h2>
      
      <div class="form-group">
        <label>商家ID</label>
        <input v-model="promotion.merchant_id" type="number">
      </div>
      
      <div class="form-group">
        <label>活动名称</label>
        <input v-model="promotion.promotion_name" type="text">
      </div>
      
      <div class="form-group">
        <label>描述</label>
        <textarea v-model="promotion.description"></textarea>
      </div>
      
      <div class="modal-actions">
        <button @click="savePromotion" class="save-btn">
          {{ isEditing? '更新' : '保存' }}
        </button>
        <button @click="closeModal" class="cancel-btn">取消</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      required: true
    },
    promotion: {
      type: Object,
      default: () => ({})
    },
    isEditing: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    savePromotion() {
      this.$emit('save', this.promotion)
    },
    closeModal() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
.promotion-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: white;
  padding: 20px;
  border-radius: 5px;
  width: 500px;
  max-width: 90%;
  position: relative;
}

.close {
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 24px;
  cursor: pointer;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.form-group textarea {
  height: 80px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.save-btn {
  padding: 8px 16px;
  background-color: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.cancel-btn {
  padding: 8px 16px;
  background-color: #6c757d;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>